// pages/songDetail/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    screenWidth: 0,
    songDetailWidth:"10%",
    imgwidth: 0,
    imgheight: 0,
    sheetInfo:{
      id: 0,
      title: "古人踏青：木落多诗藁 水韵西塘",
      author: "生如夏花",
      authorPhoto:"http://p1.music.126.net/XGisryKNPM9epLT1QC5ZaA==/109951163198881656.jpg?param=40y40",
      playNum: "2.9万",
      songNum: 10,
      thumb: "https://p.qpic.cn/music_cover/UCJDptU3vGgQt6PS5Hn6CwOCwXOGKGyUqpn0SYf8cawUeAoyIa1qtg/300?n=1"
    },
    songList:[
      {
        id: 0,
        num:1,
        title: "正在加载",
        author: "正在加载",
        album:"正在加载",
        playNum: "-"        
      }
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    this.setData({
      screenWidth: getApp().globalData.screenWidth
    }); 

    var api = getApp().globalData.API;

    wx.request({
      url: api.sheetDetail,
      data:{
        id:options.id
      },
      success: function (res, statusCode, header) {         
        that.setData({
          sheetInfo: res.data.sheetInfo,
          songList: res.data.songList
        });
      },
      fail: function (res, statusCode, header) {
      }
    });


  },
  imageLoad: function (e) {
    var _this = this;
    var $width = e.detail.width,    //获取图片真实宽度  
      $height = e.detail.height,
      ratio = $width / $height;   //图片的真实宽高比例  
    var viewWidth = (_this.data.screenWidth - 30) / 3,           //设置图片显示宽度，  
      viewHeight = viewWidth / ratio;    //计算的高度值     
    this.setData({
      imgwidth: viewWidth,
      imgheight: viewHeight,
      songDetailWidth: (_this.data.screenWidth - viewWidth-30)+"px"
    })    
  },
  songTab:function(event){
    var songId= event.currentTarget.dataset.id;
    var sheetId= this.data.sheetInfo.id;
    var that=this;
    var api = getApp().globalData.API;
    wx.request({
      url: api.SongDetail,
      data: {
        sheetId: sheetId,
        songId:songId
      },
      success: function (res, statusCode, header) {

        var audio= wx.createInnerAudioContext();
        audio.src = res.data.songUrl;
        audio.autoplay=true;
        
      },
      fail: function (res, statusCode, header) {
      }
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})